package com.cqndt.disaster.device.common.config;

import org.springframework.web.servlet.config.annotation.*;
import org.springframework.context.annotation.Configuration;
import com.cqndt.disaster.device.common.interceptor.LoginInterceptor;

/**
 * @author lgb
 * @date 2020年6月8日 下午8:02:47
 * Copyright (C) 深圳工勘科技
 * @说明: 全局跨域配置
 **/
@EnableWebMvc
@Configuration
public class GlobalWebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowedOrigins("*")
        .allowCredentials(true).allowedHeaders("*")
        .allowedMethods("GET","POST","PUT","DELETE","OPTIONS").maxAge(3600);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
    	//注册receiveInterceptor拦截器
    	InterceptorRegistration receive = registry.addInterceptor(new LoginInterceptor());
        receive.addPathPatterns("/**").excludePathPatterns("/login/getCaptcha",
        	"/login/checkCaptcha","/login/getKey","/login/logout"); 
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    	registry.addResourceHandler("/**").addResourceLocations("/","file:D:/static/");
    }
    
}